<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :cols="3" :labelWidth="110" formType="show" :isSubmitBtn="false" @formChange="formChangeHandle" />
    <FilterTable
      ref="table"
      :columns="columns"
      :datakey="'rows'"
      :height="100"
      :onColumnsChange="columns => (this.columns = columns)"
      :isColumnFilter="false"
      :isSelectColumn="false"
      :isToperInfo="false"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button type="primary" disabled>确 定</el-button>
      <el-button @click="closeDialog">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { dictionary } from '@/utils/dictMixin';
import { addRole } from '@/api/common/auth/roleManage';
import { getChargeObject } from '@/api/finance/repair/receivables';
import * as types from '@/api/common/auth/roleManage/types';

export default {
  name: 'ChargeObjectDialog',
  mixins: [dictionary],
  data() {
    this.saveData = null;
    return {
      formList: this.createFormList(),
      columns: this.createTableColumns()
    };
  },
  computed: {
    ...mapState('app', ['btnLoading']),
    addBtnState() {
      return this.btnLoading[types.YAN_ROLE_ADD];
    }
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '应收总金额',
          precision: 2,
          fieldName: 'RECEIVEABLE_AMOUNT'
        },
        {
          type: 'INPUT',
          label: '实收总金额',
          precision: 2,
          fieldName: 'REAL_RECEIVE_AMOUNT'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费对象代码',
          dataIndex: 'PAYMENT_OBJECT_CODE',
          sorter: true
        },
        {
          title: '收费对象名称',
          dataIndex: 'PAYMENT_OBJECT_NAME',
          sorter: true
        },
        {
          title: '应收金额',
          dataIndex: 'RECEIVEABLE_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '折让金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '实收金额',
          dataIndex: 'REAL_RECEIVE_AMOUNT',
          precision: 2,
          sorter: true
        }
      ];
    },
    openModel(data) {
      // console.log(data.OWNER_CODE)
      this.getChargeObject(data.OWNER_CODE, data.ITEM_ID); // 收费对象拆分
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    async getChargeObject(id, code) {
      const res = await getChargeObject(id, code);
      // console.log('res',res)
      for (let [key, value] of Object.entries(res.data[0])) {
        this.formList.some(item => {
          if (item.fieldName === key) {
            item.initialValue = value;
            return true;
          }
        });
      }
      this.$refs.table.$refs.pageTable.EXECUTE_INSERT(res.data);
    },
    closeDialog() {
      this.$emit('close', false);
    }
  }
};
</script>

<style lang="less" scoped></style>
